package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type appConfig struct {
	Mysql
	Redis
	QiNiuYun
}
type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}
type Redis struct {
	Host     string
	Port     int
	Password string
	Database int
}

type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}

var (
	Config appConfig
	err    error
)

func Init() {

	viper.SetConfigFile("./appconfig/dev.yaml")
	err = viper.ReadInConfig()
	if err != nil {
		panic("配置数据读取失败")
		return
	}
	err = viper.Unmarshal(&Config)
	if err != nil {
		panic("配置数据连接失败")
		return
	} else {
		fmt.Println("配置数据连接成功")
	}

}
